// 用户相关的接口请求函数都在这
import type { CodeType, PatientItem, User, UserInfo } from '@/types/user'
import { request } from '@/utils/request'

// 密码登录
export const loginByPassword = (mobile: string, password: string) => 
    request<User>('login/password', 'POST', { mobile, password })

// 手机验证码
export const sendMobileCode = (mobile: string, type: CodeType) =>
    request('code', 'GET', { mobile, type })

// 验证码登录
export const loginByCode = (mobile: string, code: string) => 
    request<User>('login', 'POST', { mobile, code })

// 个人信息 
export const getUserInfo = () => request<UserInfo>('patient/myUser')

// 患者信息
export const getPatientList = () => request<PatientItem[]>('patient/mylist')

// 添加患者信息
export const addPatient = (patient: PatientItem) => request('patient/add', 'POST', patient)

// 更新患者信息
export const updatePatient = (patient: PatientItem) => request('patient/update', 'PUT', patient)

// 删除患者信息
export const delPatient = (id: string) => request(`patient/del/${id}`, 'DELETE')

// 获取患者信息
export const getPatientDetial = (id: string) => request(`patient/info/${id}`, 'GET')

// qq登录
export const loginByQQ = (openId: string) =>
  request<User>('/login/thirdparty', 'POST', { openId, source: 'qq' })

// 获取验证码
export const bindMobile = (data: { mobile: string; code: string; openId: string }) =>
  request<User>('/login/binding', 'POST', data)
